package com.tegtech.api.monitor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tegtech.api.monitor.service.ISysLoginLogService;
import com.tegtech.common.domain.Result;
import com.tegtech.core.controller.BaseController;
import com.tegtech.core.page.PageResult;
import com.tegtech.starter.log.annotation.Log;
import com.tegtech.starter.log.enums.BusinessType;
import com.tegtech.starter.security.log.domain.SysLoginLog;

/**
 * 系统访问记录
 * 
 * @author Jun
 */
@RestController
@RequestMapping("/monitor/loginlog")
public class SysLoginLogController extends BaseController {
	
	@Autowired
	private ISysLoginLogService sysLoginLogService;

	@PreAuthorize("@ss.hasPermi('monitor:loginlog:list')")
	@GetMapping("/list")
	public PageResult list(SysLoginLog loginlog) {
		return buildPageResult(() -> sysLoginLogService.selectLoginLogList(loginlog));
	}

	@Log(title = "登录日志", businessType = BusinessType.EXPORT)
	@PreAuthorize("@ss.hasPermi('monitor:loginlog:export')")
	@GetMapping("/export")
	public void export(SysLoginLog loginlog) {
		List<SysLoginLog> list = sysLoginLogService.selectLoginLogList(loginlog);
		exportExcel("登陆日志", SysLoginLog.class, list);
	}

	@PreAuthorize("@ss.hasPermi('monitor:loginlog:remove')")
	@Log(title = "登录日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
	public Result remove(@PathVariable Long[] ids) {
		return toResult(sysLoginLogService.deleteLoginLogByIds(ids));
	}

	@PreAuthorize("@ss.hasPermi('monitor:loginlog:remove')")
	@Log(title = "登录日志", businessType = BusinessType.CLEAN)
	@DeleteMapping("/clean")
	public Result clean() {
		sysLoginLogService.cleanLoginLog();
		return Result.ok();
	}
}
